﻿/// Name - Common.Messaging v1.0
/// Description - This class controls functions of the system involved with sending email messages.
/// Programmer - Dan Yatzeck
/// Date coded - 10/26/2011
/// Arguments - None
/// Variables - None
/// Files accessed by this code artifact - None
/// Files changed by this code artifact - None
/// I/O - None
/// Error Handling - None
/// Modifications -
///     1.0 - Initial coding
/// Known Faults -
///     1.0 - All data is hard coded, such as sender email address, credentials, SMTP server, and 
///         registration email content.

using System.Net.Mail;

namespace Common
{
    /// <summary>
    /// Controls the email messaging functions of the system
    /// </summary>
    public class Messaging
    {
        /// <summary>
        /// Uses Gmail to send the registration email to the provided email address.
        /// </summary>
        /// <param name="emailAddress">Email recipient address</param>
        /// <param name="regcode">Registration code</param>
        public static void SendRegistrationEmail(string emailAddress, string regcode)
        {
            try
            {
                MailMessage mail = new MailMessage();
                SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

                mail.From = new MailAddress("csc440teamone@gmail.com");
                mail.To.Add(emailAddress);
                mail.Subject = "My Health Registration";
                mail.Body = "Thank you for registering with My Health.  Please enter the registration code: " + regcode;

                SmtpServer.Port = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential("csc440teamone", "dyatzeck");
                SmtpServer.EnableSsl = true;

                SmtpServer.Send(mail);
            }
            catch
            {

            }
        }
    }
}
